<!DOCTYPE html>
<html lang="en" style="background:#fff;">
<head>
    <base href="${basePath}">
    <#include "common/top.html"/>
</head>
<body style="background:#fff;">
<form class="layui-form layui-form-pamel" name="form1" id="form1" method="post">
    <div class="searchbox demoTable" id="searchbox">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">表名称：</label>
                <div class="layui-input-inline">
                    <input type="text" name="tableName" id="tableName" placeholder="请输入表名称" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">表描述：</label>
                <div class="layui-input-inline">
                    <input type="text" name="tableComment" id="tableComment" placeholder="请输入表描述" class="layui-input">
                </div>
            </div>
            <input type="button" value="查询" onclick="searchs();" class="layui-btn layui-btn-red mr10"/>
        </div>
    </div>
</form>

<div style="overflow:auto;width: 100%;padding-bottom: 20px;">
    <table id="db-table" class="layui-table" lay-filter="db-table">
    </table>
</div>

</body>
</html>

<script type="text/javascript">
    var formTable;
    var table;
    var form;

    layui.use(['form','table','laydate'], function(){
        form = layui.form;
        table = layui.table;
        form.render();
        formTable = table.render({
            elem: '#db-table',
            url:'${basePath}tool/db/list',
            method: 'post',
            where:{ti:new Date().getTime(),accountCode:'${accountCode}'},
            request: {
                pageName: 'currentPage' //页码的参数名称，默认：page
                ,limitName: 'showCount' //每页数据量的参数名，默认：limit
            },
            response: {
                statusName: 'status' //数据状态的字段名称，默认：code
                ,statusCode: true //成功的状态码，默认：0
                ,msgName: 'msg' //状态信息的字段名称，默认：msg
                ,countName: 'totalResult' //数据总数的字段名称，默认：count
                ,dataName: 't' //数据列表的字段名称，默认：data
            },
            cols: [[
                {type:'checkbox', title: '序号'}
                ,{type:'numbers', title: '序号',width:50}
                ,{field:'tableName', title: '表名称'}
                ,{field:'tableComment', title: '表描述'}
                ,{field:'createTime', title: '创建时间'}
                ,{field:'updateTime', title: '更新时间'}
            ]],
            page: true
        });

        table.on('tool(simple-table)', function(obj){
            var data = obj.data;
            if(obj.event === 'duibi'){
            }
        });
    });

    //检 索
    function searchs() {
        formTable.reload({
            where: {
                tableName: $("#tableName").val()
                ,tableComment: $("#tableComment").val()
            },page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }

    function submitHandler() {
        var tableNames = new Array();

        var checkStatus = table.checkStatus('db-table'), data = checkStatus.data;
        data.forEach(function (n,i) {
            tableNames.push(n.tableName);
        })

        $.ajax({ url: "${basePath}tool/importTable",
            data: {tables:tableNames.join()},
            type: "POST",
            success: function(data){
                if (data.status == true) {
                    layer.alert(data.msg,function(index){
                        var index1 = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index1);
                        layer.close(index);
                    });
                }else{
                    parent.layer.alert(data.msg);
                }
            }
        })

    }
</script>
